//地址
	$(".address_text").hover(function(){
		$(".address_select").show();
		if($(".address_tab span").index('.atver')!=-1)
		{
			$(".address_con").eq(0).show();	
		}
		
		
	},function(){
	
		$(".address_select").hide();
		$(".address_con").hide().eq(1).show();
		$(".address_tab i").eq(2).text('请选择').hide();
		$(".address_tab span").removeClass('atver').eq(1).addClass('atver');
	})
	$(".address_tab span").each(function(i, o) {
        $(o).click(function(){
			$(o).addClass('atver').siblings().removeClass('atver');
			$(".address_con").hide().eq(i).show();
		})
    });
	$.select_add('address_op',region_Data,1323);//默认湖北武汉江汉区
	$(".address_con").each(function(i, o) {
        $(o).html($(".address_op").eq(i).html());
		$(o).find("option").each(function(index, element) {
           $(element).wrapAll(document.createElement("span")); 
        });
		$(o).on('click','option',function(){
			$(".address_op").eq(i).val($(this).attr('value'))
			$(".address_tab span").eq(i).find('i').text($(this).text());
			var id=$(this).attr('value')
			add_div(region_Data,id,i);	
		})
    });
	
	function add_div(jsonData,id,index)
	{
			getJsonLength=function(jsonData)
			{
				var jsonLength = 1;
				for(var item in jsonData){
					jsonLength++;
				}
				return jsonLength;
			
			};
			
			var len=getJsonLength(region_Data);
			
			if(index==0)
			{
				$(".address_con").eq(1).html('');
				$(".address_con").eq(2).html('');
				$(".address_tab i").eq(1).text('请选择');
				$(".address_tab i").eq(2).text('请选择').hide();
				//for(var i=1;i<len;i++)
				for ( i in jsonData)
				{
					if(jsonData[i]!=undefined && jsonData[i]['p_region_id']==id)
					{
						$(".address_con").eq(1).append("<option value="+jsonData[i]["region_id"]+">"+jsonData[i]["local_name"]+"</option>");
						
					}
				}
				$(".address_con").eq(1).find("option").each(function(index, element) {
				   $(element).wrapAll(document.createElement("span")); 
				});
				$(".address_tab span").removeClass("atver").eq(1).addClass("atver");
				$(".address_con").hide().eq(1).show();
				
			}
			if(index==1)
			{
				$(".address_con").eq(2).html('');
				$(".address_tab i").eq(2).text('请选择').show();
				//for(var i=1;i<len;i++)
				for ( i in jsonData)
				{
					if(jsonData[i]!=undefined && jsonData[i]['p_region_id']==id)
					{
						$(".address_con").eq(2).append("<option value="+jsonData[i]["region_id"]+">"+jsonData[i]["local_name"]+"</option>")
						
					}
				}
				$(".address_con").eq(2).find("option").each(function(index, element) {
					 $(element).wrapAll(document.createElement("span")); 
				  });
				if($(".address_con").eq(2).text()=='')
				{
					$(".address_tab span").eq(2).hide().html('<i></i>');
					$(".address_text a").text($(".address_tab").text());
					$(".address_select").hide();
                    $(".input_addr").val(id);

                    installParam();

				}
				else
				{
					$(".address_tab span").eq(2).show().html('<i>请选择</i>');	

				}
				$(".address_tab span").removeClass("atver").eq(2).addClass("atver");
				$(".address_con").hide().eq(2).show();
			}
			if(index==2)
			{
					$(".address_text a").text($(".address_tab").text());
					$(".address_select").hide();
                    $(".input_addr").val(id);

                installParam();

					// doAjax('http://www.11ziyun.com/goods/getFreightprice','post',{'areaId':id,'productId':$('.productID').val(),'count':$('.action-quantity-input').val()},function(params){
                    //     $('.areaId').val(id);
                    //     $('.freightPrice').text('￥'+params['data']);
			  		// })
			}
	}
	
$(function(){
	//相册
	$.zy_scroll('.thumbnail-list','.flip_prev','.flip_next','.thumbnail-list',4,false);
	$(".thumbnail-list ul li").on('click',function(){
		$(this).addClass('atver').siblings().removeClass('atver');
		$('.product-album-preview').find("img").attr("src",$(this).find("img").attr("src")).css("opacity",0).stop().animate({opacity:1});
	});
	
	//收藏
    $(document).on('click','.addfav',function(){
        var redirect_url = 'http://www.11ziyun.com/login';
        if(redirect_url=='1'){
            if($('.addfav i').attr("value")=='1'){
//                $.alert('error', '商品已收藏',1);return;
                var goodsId = $('.goodsID').val();
                $(this).find('i').removeClass('atver');
                doAjax('http://www.11ziyun.com/member/del-collect-goods','post',{'goodsId':goodsId},function(data){
                    if(data['result']=='1'){
                        $('.addfav i').attr('value',0)
                        $.alert('success', '取消成功');return;
                    }else{
                        $.alert('error', '取消失败');return;
                    }
                })
            }else{
                var info = {};
                info['goodsIds'] = $('.goodsID').val();
                $(this).find('i').addClass('atver')
                doAjax('http://www.11ziyun.com/member/do-collect-goods','post',info,function(data){
                    if(data['result']=='1'){
                        $('.addfav i').attr('value',1)
                        $.alert('success', '收藏成功');return;
                    }else{
                        $.alert('error', '收藏失败');return;
                    }
                })
            }
        }
        else{
            window.location.href=redirect_url;return;
        }
    })
	
	
	
	//减少数量
        $(document).on('click','.btn-decrease',function(){
            var pic_buy='';
            var input_obj = $(".action-quantity-input");
            var cur_val = Number(input_obj.val());
            if(cur_val  <=1 )return;
            CountAnim(this,cur_val+'',(cur_val-1)+'',-40);
            input_obj.val(Number(cur_val-1));
			if($('.product-big-title span.atver').attr('unit')=='ream')
			{
				pic_buy=Number($('.lPrice').val());
			}
			else if($('.product-big-title span.atver').attr('unit')=='ton')
			{
				pic_buy=Number($('.dPrice').val())
			}
			else if($('.spec-price-box-design.atver').attr('design_cost'))
			{
				pic_buy=Number($('.spec-price-box-design.atver').attr('design_cost'))
				$('.design_cost').text(pic_buy*input_obj.val())
                var urgent = $('.urgent_box .atver').attr('urgent');
                $('.select-design_urgent').text(urgent*input_obj.val());
			}
			else
			{
				pic_buy=Number($('input.price').val())
			}
			if($('.urgent_button').hasClass('atver'))
			{
				$('.urgent').text(input_obj.val()*Number($('.urgent_button').attr('urgent')))
				
			}

			num_data(pic_buy,input_obj.val())
//            if($('.addcartBuyType').val()=='design_service'){
//                $(".total_num").text(Number($(".select-design_cost").text())+Number($(".select-design_urgent").text()))
//            }else{
//                $(".total_num").text(Number($(".design_cost").text())+Number($(".urgent").text()))
//            }
        });
		
		 //增加数量
        $(document).on('click','.btn-increase',function(){

            var input_obj = $(".action-quantity-input");
            var cur_val = Number(input_obj.val());
            var store = $('.store').val();
            var nostoreSell = $('.nostoreSell').val();
            if(cur_val  >=99999 )return;
//            if(!nostoreSell)
//            {
//                if(input_obj.val()>=store)
//                {
//                    $.alert('error', '库存不足');return;
//                }
//            }
            CountAnim(this,cur_val+'',(cur_val+1)+'',-40);
            input_obj.val(Number(cur_val+1));
			var pic_buy='';
			if($('.product-big-title span.atver').attr('unit')=='ream')
			{
				pic_buy=Number($('.lPrice').val())
			}
			else if($('.product-big-title span.atver').attr('unit')=='ton')
			{
				pic_buy=Number($('.dPrice').val())
			}
			else if($('.spec-price-box-design.atver').attr('design_cost'))
			{
				pic_buy=Number($('.spec-price-box-design.atver').attr('design_cost'))
				$('.design_cost').text(pic_buy*input_obj.val())
                var urgent = $('.urgent_box .atver').attr('urgent');
                $('.select-design_urgent').text(urgent*input_obj.val());
			}
			else
			{
				pic_buy=Number($('input.price').val())
			}
			if($('.urgent_button').hasClass('atver'))
			{
				$('.urgent').text(input_obj.val()*Number($('.urgent_button').attr('urgent')))
			}

			num_data(pic_buy,input_obj.val());
//            if($('.addcartBuyType').val()=='design_service'){
//                $(".total_num").text(Number($(".select-design_cost").text())+Number($(".select-design_urgent").text()))
//            }else{
//                $(".total_num").text(Number($(".design_cost").text())+Number($(".urgent").text()))
//            }
        });
	
	$(document).on('change','.action-quantity-input',function(){
			var pic_buy='';
            var num = $(this).val();
            if(isNaN(num)){
                $(this).val(1);return;
            }
			if($('.product-big-title span.atver').attr('unit')=='ream')
			{
				pic_buy=Number($('.lPrice').val());
                num = Number(num).toFixed(3);
			}
			else if($('.product-big-title span.atver').attr('unit')=='ton')
			{
				pic_buy=Number($('.dPrice').val());
                num = Number(num).toFixed(6);
			}
			else if($('.spec-price-box-design.atver').attr('design_cost'))
			{
                var urgent = $('.urgent_box .atver').attr('urgent');
				pic_buy=Number($('.spec-price-box-design.atver').attr('design_cost'))
				$('.design_cost').text(pic_buy*$(this).val());
                $('.select-design_urgent').text(urgent*$(this).val());
                num = Number(num).toFixed(0);
			}
			else
			{
//                var store = $('.store').val();
//                var nostoreSell = $('.nostoreSell').val();
//                if(!nostoreSell)
//                {
//                    if(num>=store)
//                    {
//                        $.alert('error', '库存不足');
//                        num = store;
//                        $(this).val(store);
//                    }
//                }
				pic_buy=Number($('input.price').val());
                num = Number(num).toFixed(0);
			}
			if($('.urgent_button').hasClass('atver'))
			{
				$('.urgent').text($(this).val()*Number($('.urgent_button').attr('urgent')))
			}
//            if($('.addcartBuyType').val()=='design_service'){
//                $(".total_num").text(Number($(".select-design_cost").text())+Number($(".select-design_urgent").text()))
//            }else{
//                $(".total_num").text(Number($(".design_cost").text())+Number($(".urgent").text()))
//            }
			num_data(pic_buy,num)
		})
		//数量加减计算
		function num_data(pic,num,dis)
		{
            var goodsType =$('#goodsType').val();
            var info = {};
            if(num>=99999){
                num = 99999;
            }

            installParam();//组装参数


          /*  if(addcartBuyType=='print' || addcartBuyType=='fold')
            {
                info['productId']=$('.productID').val();
                info['count']=num;
                var craid = '';
                for(var i=0;i<$(".Craft span.atver").length;i++)
                {
                    craid+=$(".Craft span.atver").eq(i).attr('cravalueid')+','
                }
                craid=craid.substring(0,craid.length-1);
                info['craIds']=craid;
            }else if(addcartBuyType=='paper'){
                info['productid']=$('.productID').val();
                info['pu']=$.trim($('.unit').val());
                if(info['pu']=='ream'){
                    info['width']=$('.width').val();
                    info['length']=$('.length').val();
                }
                info['number']=num;
            }else if(addcartBuyType=='copy'){
                var min = $.trim($('.action-quantity-input').attr('min'));
                min = parseInt(min);
                num = parseInt(num);
                if(min > num){
                    num = min;
                    $('.action-quantity-input').val(num);
                    $.alert('error', '起订量过小');
                }
                info['productId']=$('.productID').val();
                info['count']=num;
            }else{
                info['productId']=$('.productID').val();
                info['count']=num;
            }

            if(addcartBuyType=='paper'){
                if(info['pu']=='ream'){
                    if(info['width']=='' || info['length']==''){
                        return;
                    }
                }
                doAjax('http://www.11ziyun.com/goods/getPaperprice','',info,function(list){
                    if(list['result']=='1') {
                        var totle = list['data']['totalPrice'];
                        $('.action-price b').text(totle);
                        $('.lPrice_buy').text('￥' + list['data']['lPrice']);
                        $('.action-quantity-input').val(list['data']['number']);
                    }
                    else
                    {
                        $.alert('error', list['message']);
                    }
                })
            }else{
                info['addcartBuyType']=addcartBuyType;
                info['areaId']=$('.areaId').val();
                doAjax('http://www.11ziyun.com/goods/productBase','post',info,function(params) {
                    if(params['result']=='1'){
                        if(addcartBuyType=='design_service'){
                            $('.select-design_cost').text(params['data']['totalPrice']);
                            if($('.urgent_box .atver').attr('urgent')>0){
                                $('.select-design_urgent').text(params['data']['totalPrice']/2);
                            }
                        }
                        $('.action-price b').text(params['data']['totalPrice']);
                        $('.weight').html(params['data']['weight']+'kg');
                        $('.freightPrice').text('￥'+params['data']['freightPrice']);
                        $('.action-quantity-input').val(params['data']['count']);
                        if($('.addcartBuyType').val()=='design_service'){
                            $(".total_num").text(Number($(".select-design_cost").text())+Number($(".select-design_urgent").text()))
                        }else{
                            $(".total_num").text(Number($(".design_cost").text())+Number($(".urgent").text()))
                        }
                    }
                    else
                    {
                        $.alert('error', params['message']);
                        if(params['code']==1305){
                            $('.action-quantity-input').val(params['data']['count']);
                        }
                        if(params['message']=='超过库存数'){
                            $('.action-quantity-input').val($('.store').val());
                        }
                    }
                })
            }*/
		}
		
		var CountAnim=function(obj,j,l,num){
            var txtCount = $('.action-quantity-input');
            var p=$(obj).parents('.input_box');
            var k='';
            var j=j.split('');
            txtCount.css('color','#fff');
            for (var s = 0; s < j.length; s++)
            {
                k += '<i style="position:relative;">' + j[s] + "</i>";
            }
            p.prepend('<i class="upspan" >' + k + "</i>");

            var m='';
            var l=l.split('');
            for (var n = 0; n <l.length; n++)
            {
                m += '<i style="position:relative;">' + l[n] + '</i>';

            }
            p.append('<i class="downspan" style="top:'+(-num)+'px;">' + m + "</i>");
            var d = $(".downspan i:last");
            var u= $(".upspan i:last");

            u.animate({top: num}, "10");
            d.animate({top: num}, "10",function(){
               $('.downspan,.upspan').remove();
                txtCount.css('color','#333');
            });
        }


})



///**************************************************************************************

//监听尺寸输入框变化
$("input.length,input.flagLength").change(function () {
    installParam();
});

$("span.urgent,span.Nourgent").click(function () {
    $(this).addClass('atver').siblings().removeClass('atver');
    if($(this).attr('specvalueid') == -6){
       var money = parseInt($("#designPrice").text())/2+parseInt($("#designPrice").text());
        $("#designPrice").text(money);
    }else{
        var money = parseInt($("#designPrice").text())*2/3;
        $("#designPrice").text(money);
    }
})


//点击 切换样式 并传参数
$(".product-big-title .paper").each(function(i,o){

    $(o).click(function(){
        if($(this).hasClass('atver'))
        {
            return;
        }
        if($(".product-big-title .paper").length>1)
        {
            if($(this).attr('unit') == 'ton'){
                $("div.ream").hide();
                $("div.ton").show();
            }else{
                $("div.ream").show();
                $("div.ton").hide();
            }

            $(this).addClass('atver').siblings().removeClass('atver');
            $('.product-big-con ul').css("display",'none').eq(i).css("display",'block');
        }

    });
});


$(document).on('click','.product-buy .item-content .spec-attr, .product-big-con ul li .spec-attr',function(){


    //点击切换样式
    if($(this).attr('specvalueid')){
        if(!$(this).hasClass('atver')){
            $(this).addClass('atver').siblings().removeClass('atver');
            //判断是否是设计产品
            if($(this).hasClass('design')){
                var partAndAttrRelateOptListMap = {};
                $("span.Nourgent").addClass('atver').siblings().removeClass('atver');

                $("span.partParam").each(function () {
                    var attributeOptionNames = [];
                    $(this).find(".designDto:visible").each(function () {
                        var obj = $(this);
                        $(this).find("span.spec-attr").each(function () {
                            if($(this).hasClass("atver")){
                                var attrOpt = {};
                                attrOpt['optionId'] = $(this).attr('specvalueid');
                                var squre = {};
                                squre['id'] = obj.find("span[optionId]").attr('optionId');
                                squre['attributeType'] = obj.find("span[optionId]").attr('attributeType');
                                squre['attributeKey'] = obj.find("span[optionId]").attr('attributeKey');
                                squre['influenceCraftPriceType'] = obj.find("span[optionId]").attr('influenceCraftPriceType');
                                squre['joinBuildSku'] = obj.find("span[optionId]").attr('joinBuildSku');

                                attrOpt['squareVO'] = squre;
                                attributeOptionNames.push(attrOpt);
                            }
                        });
                    });
                    var partId = $(this).attr("partId");
                    partAndAttrRelateOptListMap[partId] = attributeOptionNames;

                })

                // var attributeOptionNames = [];
                // var obj = $(".designDto");
                //     $(".designDto").find("span.spec-attr").each(function () {
                //         if($(this).hasClass("atver")&&$(this).hasClass('design')){
                //             var attrOpt = {};
                //             attrOpt['optionId'] = $(this).attr('specvalueid');
                //             var squre = {};
                //             squre['id'] = obj.find("span[optionId]").attr('optionId');
                //             squre['attributeType'] = obj.find("span[optionId]").attr('attributeType');
                //             squre['attributeKey'] = obj.find("span[optionId]").attr('attributeKey');
                //             squre['influenceCraftPriceType'] = obj.find("span[optionId]").attr('influenceCraftPriceType');
                //             attrOpt['squareVO'] = squre;
                //             attributeOptionNames.push(attrOpt);
                //         }
                //     });

                var goodsParamsVO = {};
                $("input[type=hidden].parameter").each(function () {
                    var name = $(this).attr('id');
                    var value = $(this).val();
                    if(name=='spuId'){
                        goodsParamsVO['goodsId'] = value;
                    }else{
                        goodsParamsVO[name] = value;
                    }
                });
                goodsParamsVO['quantity'] = $("input.action-quantity-input").val();//组装数量
                goodsParamsVO['areaId'] = $(".input_addr").val();

                // var attrRelateOptList = attributeOptionNames();//页面参数 []


                var url = "/goods/getSellPrice.json";
                var paramsVO = JSON.stringify(goodsParamsVO);
                var list = JSON.stringify(partAndAttrRelateOptListMap);

                doAjax(url,'post',{"goodsParamsVO":paramsVO,"attrRelateOptList":list},function (ret) {
                    if(ret.code=='1'){
                        var html = ret.data.basePriceDetail.totalPrice;
                        $("#designPrice").text(html);
                        $("span.cont").show();
                        $(".designHtml").show();
                    }
                });
                return;
            }
        }else{
            if($(this).hasClass('craft')||$(this).hasClass('design')){
                if(!$(this).hasClass('must')){
                $(this).removeClass('atver');
                }
                //如果是设计产品
                if($(this).hasClass('design')){
                    $(".designHtml").hide();
                }
            }
        }


        //判断如果有大纸尺寸参数，需要页面变化参数

        if($(this).hasClass('paper_spec')){
            var obj = $(this);
            var optionWid = $(this).attr('optionWid');
            var optionLen = $(this).attr('optionLen');
           obj.parents("li").siblings("li.product-big-unusual").find("input").each(function (i,o) {
                if(!obj.attr('very')&&i==0){
                $(o).prop('readonly',true);
                    $(o).val(optionWid);
                }else if(!obj.attr('very')&&i==1){
                $(o).prop('readonly',true);
                    $(o).val(optionLen);
                }else{
                    $(o).removeAttr('readonly');
                    $(o).val(optionWid);
                    $(".hidInput").val(0);
                }
            })
        }

        if($(this).attr('very')){ //如果是特规 则不返回
            return;
        }

        installParam();
    }
});


//组装参数发送ajax请求

function installParam() {

    var goodsParamsVO = {};
    var goodsType = $('#goodsType').val();

    var attrRelateOptList = attributeOptionNames();


    if(goodsType == 'paper'){
        var width = $(".width:visible").val();
        var length = $(".length:visible").val();
        if(!length){
            length = 0;
        }
        goodsParamsVO['paperWidth'] = width;
        goodsParamsVO['paperLength'] = length;
    }


    $("input[type=hidden].parameter").each(function () {
        var name = $(this).attr('id');
        var value = $(this).val();
        if(name=='spuId'){
            goodsParamsVO['goodsId'] = value;
        }else{
            goodsParamsVO[name] = value;
        }
    });
    goodsParamsVO['quantity'] = $("input.action-quantity-input").val();//组装数量
    goodsParamsVO['areaId'] = $(".input_addr").val();

    // var attrRelateOptList = attributeOptionNames();//页面参数 []

    if($("input.action-quantity-input").val()>store){
        if(!isNoStoreSell){
            $.alert("error","所选商品超过库存",1);
            return;
        }
    }


    var url = "/goods/getSellPrice.json";
    var paramsVO = JSON.stringify(goodsParamsVO);
    var list = JSON.stringify(attrRelateOptList)
    doAjax(url,'post',{"goodsParamsVO":paramsVO,"attrRelateOptList":list},function (ret) {
        console.log(ret);
        if(ret.code=='1'){

            var html = template('standradDetails', ret.data);
            $("div#rightHtml").remove();
            $("div.page-maincontent").append(html);

            // var goodsInfo = ret.data;
            // var goodsType = $('#goodsType').val();
            // if(goodsType == 'standard'){
            //     //首先将数据放入到页面上
            //     $("span.freightPrice").find("strong").text(goodsInfo.basePriceDetail.freightPrice);
            //     $("span.singlePrice").find("strong").text(goodsInfo.basePriceDetail.singlePrice);
            //     $("span.totalPrice").find("strong").text(goodsInfo.basePriceDetail.totalPrice);
            //     $("#id").val(goodsInfo.basePriceDetail.productId);
            //     $("#store").val(goodsInfo.store);
            // }else if(goodsType == 'paper'){
            //     //判断当前是卷筒还是大纸
            //     var unit = $("div.product-big-title").find("span.atver").attr('unit');
            //     if(unit == 'ton'){
            //         $("span.tonTonPrice").find("strong").text(goodsInfo.basePriceDetail.coilingTonPrice);
            //         $("span.tonTotalPrice").find("strong").text(goodsInfo.basePriceDetail.coilingTonPrice);
            //         $("#id").val(goodsInfo.basePriceDetail.productId);
            //         $("#store").val(goodsInfo.store);
            //     }else if(unit == 'ream'){
            //         $("span.plateLPrice").find("strong").text(goodsInfo.basePriceDetail.plateLPrice);
            //         $("span.reamTonPrice").find("strong").text(goodsInfo.basePriceDetail.expandPrice);
            //         $("span.reamTotalPrice").find("strong").text(goodsInfo.basePriceDetail.totalPrice);
            //         $("#id").val(goodsInfo.basePriceDetail.productId);
            //         $("#store").val(goodsInfo.store);
            //     }
            // }
        }else{
            $.alert("error",ret.message,1);
        }
    });
}


//页面sku组装array;
function attributeOptionNames() {

    var partAndAttrRelateOptListMap = {};

    $("span.partParam").each(function () {
    var attributeOptionNames = [];
        $(this).find(".AttributeOptionDto:visible").each(function () {
            var obj = $(this);
            $(this).find("span.spec-attr").each(function () {
                if($(this).hasClass("atver")){
                    var attrOpt = {};
                    attrOpt['optionId'] = $(this).attr('specvalueid');
                    var squre = {};
                    squre['id'] = obj.find("span[optionId]").attr('optionId');
                    squre['attributeType'] = obj.find("span[optionId]").attr('attributeType');
                    squre['attributeKey'] = obj.find("span[optionId]").attr('attributeKey');
                    squre['influenceCraftPriceType'] = obj.find("span[optionId]").attr('influenceCraftPriceType');
                    squre['joinBuildSku'] = obj.find("span[optionId]").attr('joinBuildSku');

                    attrOpt['squareVO'] = squre;
                    attributeOptionNames.push(attrOpt);
                }
            });
        });
        var partId = $(this).attr("partId");
        partAndAttrRelateOptListMap[partId] = attributeOptionNames;

    })

    // $(".partParam .AttributeOptionDto:visible").each(function () {
    //     var obj = $(this);
    //     $(this).find("span.spec-attr").each(function () {
    //         if($(this).hasClass("atver")){
    //             var attrOpt = {};
    //             attrOpt['optionId'] = $(this).attr('specvalueid');
    //             var squre = {};
    //             squre['id'] = obj.find("span[optionId]").attr('optionId');
    //             squre['attributeType'] = obj.find("span[optionId]").attr('attributeType');
    //             squre['attributeKey'] = obj.find("span[optionId]").attr('attributeKey');
    //             squre['influenceCraftPriceType'] = obj.find("span[optionId]").attr('influenceCraftPriceType');
    //             squre['joinBuildSku'] = obj.find("span[optionId]").attr('joinBuildSku');
    //
    //             attrOpt['squareVO'] = squre;
    //             attributeOptionNames.push(attrOpt);
    //         }
    //     });
    //     var partId = $(this).parent("span").attr("partId");
    //     partAndAttrRelateOptListMap['partId'] = partId;
    //     partAndAttrRelateOptListMap['AttrRelateOpt'] = attributeOptionNames;
    //     partAndAttrRelateOptList.push(partAndAttrRelateOptListMap);
    // });

    return partAndAttrRelateOptListMap;
}

//大纸参数组装*************************************
// function attributeOptionMap(){
// 	    var map = {};
// 	    var attrRelateOptList = [];
// 	    var selfDefineParams = {};
//     //找到当前显示的li组装数据
//     $("div.product-big-con").find("ul li.prodcut-must:visible").each(function () {
//         var attrOpt = {};
//         var obj = $(this);//当前li 属性
//         var $span = $(this).find("span.atver");//被选中的属性 如果不是自定义
//
//         if(!$span.attr('very')){
//             attrOpt['optionid'] = $span.attr('specvalueid');
//             var squre = {};
//             squre['id'] = $(obj.find("label").get(0)).attr('optionid');
//             squre['attributeType'] = $(obj.find("label").get(0)).attr('attributetype');
//             squre['attributeKey'] = $(obj.find("label").get(0)).attr('attributekey');
//             squre['influenceCraftPriceType'] = $(obj.find("label").get(0)).attr('influenceCraftPriceType');
//             attrOpt['squareVO'] = squre;
//             attrRelateOptList.push(attrOpt);
//         }else{
//             var param = "";
//             var customlimitvalue =  $(obj.find("label").get(0)).attr('customlimitvalue');
//             var optionId = $(obj.find("label").get(0)).attr('optionid');
//
//             $($("div.product-big-con").find("ul li.product-big-unusual:visible").get(0)).find("input").each(function (i,o) {
//                 param+=$(o).val()+",";
//
//             });
//            param = "["+ param.substr(0,param.length-1)+"]";
//
//             selfDefineParams[optionId] = param;
//         }
//     });
//
//     map['attrRelateOptList'] = attrRelateOptList;
//     map['selfDefineParams'] = selfDefineParams;
//     return map;
// }


//商品 加 购物车 或立即购买
$(document).on('click','.action-addtocart',function () {
    var addCartDto = {};
    var designDto = [];
    var goodsType = $('#goodsType').val();

    $("input[type=hidden].parameter").each(function () {
        var name = $(this).attr('id');
        var value = $(this).val();
        addCartDto[name] = value;
        // if(name!='id' && name!='spuId'){
        // }else if(name == 'spuId'){
        //     addCartDto['id'] = value;
        // }
    });
    addCartDto['quantity'] = $("input.action-quantity-input").val();//组装数量
    var type = $(this).attr("id");
    if(type=='addcart'){
    addCartDto['operateType'] = 'addcart';
    }else{
    addCartDto['operateType'] = 'buynow';
    }

    if(goodsType == 'paper'){
        var width = $(".width:visible").val();
        var length = $(".length:visible").val();
        if(!length){
            length = 0;
        }
        addCartDto['paperWidth'] = width;
        addCartDto['paperLength'] = length;
    }

    var attributeOptionName = attributeOptionNames();

    //判断是否有设计商品 如果有 组装参数
    var designLen = $("div.product-buy").find("div.designDto").length;

    // if(designLen >=1){
    //     var trussDtoList = [];
    //     var TrussDto = {};
    //     $("dov.product-buy").find("div.designDto").each(function () {
    //         var obj = $(this);
    //         TrussDto['trussSkuId'] = obj.find("span[optionId]").attr('optionId');
    //
    //         $(this).find("span.spec-attr").each(function () {
    //             if($(this).hasClass("atver")){
    //                 var attrOpt = {};
    //                 debugger;
    //                 attrOpt['optionId'] = $(this).attr('specvalueid');
    //                 var squre = {};
    //                 squre['id'] = obj.find("span[optionId]").attr('optionId');
    //                 squre['attributeType'] = obj.find("span[optionId]").attr('attributeType');
    //                 squre['attributeKey'] = obj.find("span[optionId]").attr('attributeKey');
    //                 squre['influenceCraftPriceType'] = obj.find("span[optionId]").attr('influenceCraftPriceType');
    //                 squre['joinBuildSku'] = obj.find("span[optionId]").attr('joinBuildSku');
    //
    //                 attrOpt['squareVO'] = squre;
    //                 attributeOptionNames.push(attrOpt);
    //             }
    //         });
    //     })
    //
    // }

    console.log(JSON.stringify(addCartDto));

    //判断是否够库存，是否可以超库存销售
    var store = $("#store").val();//库存
    var isNoStoreSell = $("#isNoStoreSell").val();//是否支持超

    if(addCartDto['quantity']>store){
        if(!isNoStoreSell){
            $.alert("error","所选商品超过库存",1);
            return;
        }
    }
    if(type=='addcart'){//添加购物车
    	 doAjax("/cart/productAddCart","post",{"attributeOptionNames":JSON.stringify(attributeOptionName),"addCartDto":JSON.stringify(addCartDto)},function () {
    	        
    	        $.alert("success","添加购物车成功",1);
    	       
    	    })
    }else{
        doAjax("/order/popGoDown/bzRedirectIndex.json","post",{"attributeOptionNames":JSON.stringify(attributeOptionName),"addCartDto":JSON.stringify(addCartDto)},function (ret) {
        	$.alert("success","立即购买",1);
	        var url="/order/popGoDown/bzIndex.do";
	        location.href = url;
	       
	    })
    }
   
    

});